package ude.univ.esiag.gon.uchiha.gui;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ude.univ.esiag.gon.uchiha.register.Multicaster;
import ude.univ.esiag.gon.uchiha.topic.Topic;

public class MyFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	private JTextField topicName;
	private JButton topicValidate1;
	public MyFrame() {
		this.setTitle("Instance DCS");
		this.setSize(600, 400);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setAlwaysOnTop(true);
		this.setLayout(new GridLayout(2, 1));
		topicName = new JTextField("com", 10);
		topicValidate1 = new JButton("Valider1");
		JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		topicValidate1.addActionListener(new ValiderTopicName1(topicName, panel3));
		JPanel panel1 = new JPanel(new GridLayout(1, 3));
		JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel2.add(new Label("Topic Name"));
		panel1.add(panel2);
		panel2 = new JPanel();
		panel2.add(topicName);
		panel1.add(panel2);
		panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel2.add(topicValidate1);
		panel1.add(panel2);
		this.add(panel1);
		this.add(panel3);
		this.setVisible(true);
		Multicaster.getInstance().startUp();
	}
	public class ValiderTopicName1 implements ActionListener{
		private JTextField field;
		private JPanel panel;
		public ValiderTopicName1(JTextField field, JPanel panel) {
			this.field = field;
			this.panel = panel;
		}
		public void actionPerformed(ActionEvent e) {
			String topicName = field.getText();
			Topic topic = new Topic(topicName, topicName);
			TopicPanel panel1 = new TopicPanel(panel);
			topic.addTopicListener(panel1);
			panel1.modifiedTopic(topic);
		}
	}
	public static void main(String[] args) {
		new MyFrame();
	}
}
